package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记
 */
@Getter
@Setter
@ToString
@JsonIgnoreProperties("handler")
public class Travel extends BaseDomain{
    public static final Integer STATE_DRAFT = 0;//草稿
    public static final Integer STATE_TOAUDIT = 1;//待审核
    public static final Integer STATE_RELEASED = 2;//已发布
    public static final Integer STATE_REFUSED = -1;//已拒绝

    //标题
    private String title;
    //旅行时间
    //控制返回数据的转换格式
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    //控制接收参数的转换格式
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    //人均支出
    private String perExpends;
    //旅行天数
    private Integer days;
    //旅行人数
    private Integer person;
    //作者
    private User author;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //是否公开
    private Boolean isPublic = false;
    //旅游地
    private Region place;
    //游记封面
    private String coverUrl;
    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date lastUpdateTime;
    //状态 0 草稿/1 待审核/2 已发布/3 已拒绝
    private Integer state = STATE_DRAFT;

    //游记内容
    private TravelContent travelContent;

    //关联被收藏数
    private int collectionNum;
    //浏览量
    private int browseNum;

    //点赞数(不用出现在数据库字段中)
    private Integer likeNum;

    //是否已经点赞(不用出现在数据库字段中)
    private boolean like;

    //评论数
    private int commentNum;

    //状态字符串
    public String getStateString(){
        if (state != null) {
            if (state==STATE_DRAFT){
                return "草稿";
            }else if (state==STATE_TOAUDIT){
                return "待审核";
            }else if (state==STATE_RELEASED){
                return "已发布";
            }else {
                return "已拒绝";
            }
        }
        return null;
    }

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("state",state);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSON.toJSONString(map);
    }

    public String getPersonString(){
        String temp = "一个人的旅行";
        if (person != null) {
            if (person==2){
                temp = "和父母";
            }else if (person==3){
                temp = "和朋友";
            }else if (person==4){
                temp = "和同事";
            }else if (person==5){
                temp = "和爱人";
            }else if (person==6){
                temp = "和其他";
            }
            return temp;
        }
        return null;

    }

}